Page({
  data: {
    dialogVisible: false,
  },

  onLoad() {
    this.getList()
  },
  async getList() {
    const list = await wx.http({
      url: '/room'
    })
    list.forEach(item => {
      switch (item.status) {
        case 1:
          item.statusText = '审核中',
            item.statusClass = 'info'
          break
        case 2:
          item.statusText = '审核成功',
            item.statusClass = 'success'
          break
        case 3:
          item.statusText = '审核失败',
            item.statusClass = 'fail'
          break
      }
    })
    this.setData({ list })
  },
  swipeClose(ev) {
    console.log('123', ev);
    this.id = ev.mark.id
    this.index = ev.mark.index
    const { position, instance } = ev.detail

    if (position === 'right') {
      // 显示 Dialog 对话框
      this.setData({
        dialogVisible: true,
      })

      // swiper-cell 滑块关闭
      instance.close()
    }
  },

  async dialogClose(ev) {
    if (ev.detail === 'cancel') return
    if (ev.detail === 'confirm') {
      await wx.http({
        url: `/room/${this.id}`,
        method: 'DELETE',
      })
      wx.showToast({
        title: '删除成功',
      })
      this.data.list.splice(this.index, 1)
      this.setData({ list: this.data.list })
    }
  },
  goDetail(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/detail/index?id=' + ev.mark.id,
    })
  },

  addHouse() {
    wx.navigateTo({
      url: '/house_pkg/pages/locate/index',
    })
  },
})
